
package at.momberban.game.me.tests;


import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import at.momberban.game.me.Media;


public final class MediaTester extends MIDlet implements CommandListener {

    private List l = new List("MediaTester", List.IMPLICIT);
    private Command exit = new Command("Exit", Command.EXIT, 1);
    private Command playMusic = new Command("Play music", Command.OK, 1);
    private Command stopMusic = new Command("Stop music", Command.CANCEL, 1);
    private Command sfx = new Command("Play SFX", Command.OK, 1);
    
    public MediaTester() {
        l.addCommand(exit);
        l.addCommand(sfx);
        l.addCommand(playMusic);
        l.setCommandListener(this);
    }


    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    // TODO Auto-generated method stub

    }


    protected void pauseApp() {
    // TODO Auto-generated method stub

    }


    protected void startApp() throws MIDletStateChangeException {
        l.deleteAll();
        Display.getDisplay(this).setCurrent(l);
        l.append("MP3 supp: " + Media.hasMP3Support(), null);
        l.append("MIDI supp: " + Media.hasMIDISupport(), null);
    }


    public void commandAction(Command c, Displayable arg1) {
        if (c == exit) {
            try {
                destroyApp(false);
                notifyDestroyed();
            } catch (final MIDletStateChangeException ex) {
                // Ignore
            }
        } else if (c == sfx) {
            Media.playExplosionSound();
        } else if (c == playMusic) {
            l.removeCommand(playMusic);
            l.addCommand(stopMusic);
            Media.playBackgroundMusic();   
        } else if (c == stopMusic) {
            l.removeCommand(stopMusic);
            l.addCommand(playMusic);
            Media.stopBackgroundMusic();
        }
    }

}
